package com.sharding.controller;

import com.alibaba.fastjson.JSON;
import com.sharding.dto.Order;
import com.sharding.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @author wl
 * @Description: 订单控制层
 * @date 2018/12/1410:54
 */
@RestController
public class OrderController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Autowired
    OrderService orderService;

    @PostMapping(value = "createOrder")
    public Object createOrder(Order order){
        order.setId(UUID.randomUUID().toString().replaceAll("-",""));
        System.out.println(order.getName());
        System.out.println(order.getSize());
        System.out.println(order.getId());
        logger.info(JSON.toJSONString(order));
        int result = orderService.insertOrder(order);
        return order;
    }
    @GetMapping(value = "getOrder")
    public Object getOrder(){
        return orderService.selectAllOrder();
    }


}
